package cn.ytxy.ivos.vehicle.controller;


import cn.ytxy.ivos.base.response.JsonResult;
import cn.ytxy.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.ytxy.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.ytxy.ivos.vehicle.pojo.vo.VehicleVO;
import cn.ytxy.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

/**
 * @ClassName VehicleController
 * @Description TODO
 * @Author renhong~Deng
 * @Date 2025/4/28 16:17
 * @Version 1.0
 */

@Slf4j
@RestController
@RequestMapping("/v1/vehicle/")
public class VehicleController {

    @Autowired
    VehicleService vehicleService;

    @GetMapping("/select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆信息，VehicleQuery={}", vehicleQuery);
        System.out.println(vehicleQuery);
        List<VehicleVO> vehicleVOList = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(vehicleVOList);
    }


    @PostMapping("/save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam) {
        log.debug("保存车辆信息，vehicleSaveParam={}", vehicleSaveParam);
        //注意新增+更新都在此接口实现类中
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id) {
        log.debug("删除车辆信息，id={}", id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }


    @PostMapping("/unbind/{vehicleId}")
    public JsonResult unbindVehicle(@PathVariable Long vehicleId) {
        log.debug("解绑车辆，vehicleId={}", vehicleId);
        vehicleService.unbindVehicle(vehicleId);
        return JsonResult.ok();

    }

    @PostMapping("/bind/{geofenceId}/{vehicleId}")
    public JsonResult bindVehicle(@PathVariable Long geofenceId,@PathVariable Long vehicleId){
        log.debug("绑定车辆，geoId={},vehicleId={}",geofenceId,vehicleId);
        vehicleService.bindVehicle(geofenceId,vehicleId);
        return JsonResult.ok();
    }
}
